import React, { Component, PropTypes } from 'react';
import {
  WingBlank, WhiteSpace, Grid, Flex, Card, InputItem, List, Button, Modal,
} from 'antd-mobile';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import { GENDER_MAP } from 'const';
import { createForm } from 'rc-form';
import styles from './styles.less';

const { Item, Item: { Brief } } = List;
const TongueSavlePage = ({ dispatch, location, step2, form, ...rest}) => {
  const { getFieldProps, getFieldValue, setFieldsValue, validateFields, getFieldError } = form;
  const dele = () => {
    Modal.alert('确认要退出吗？', '此条记录将不会被保存', [
      { text: '取消', onPress() { } },
      { text: '确定', onPress: () => {
        dispatch(
            routerRedux.replace({
               pathname: `/healthy/diagnosis`,
          })
        );
      }}
    ]);
    
  };

  const keep = () => {
     dispatch({
        type: 'tongue/saveTongue',
        payload: {
          id: step2.tongueId,
          patientId:location.state.patientId,
          sheSe: step2.sheSe, 
          bianJianHong: step2.bianJianHong, 
          yuBanYuDian: step2.yuBanYuDian, 
          taiSe: step2.taiSe, 
          houBao: step2.houBao, 
          ni: step2.ni, 
          fu: step2.fu, 
          taiBao: step2.taiBao, 
          pangShou: step2.pangShou, 
          chiHen: step2.chiHen, 
          dianCi: step2.dianCi, 
          lieWen: step2.lieWen,
          moistDry: step2.moistDry,
          toughTender: step2.toughTender,
          comment: getFieldValue('comment'),
         },
       }
     );
  };
  return (
    <div>
       <WhiteSpace />
      <WingBlank size="md">
        <List wrap>
          <Item extra={null}>舌图：
            <Brief>
              <img src={step2.step1Pic} className={styles.tongueImageOriginal} />
            </Brief>
            <WhiteSpace size="xl" />
            <Brief>
              <img src={step2.step2Pic} className={styles.tongueImageOriginal} />
            </Brief>
            <WhiteSpace size="xl" />
          </Item>
           <List wrap>
           <InputItem
                {...getFieldProps('comment', {
                  validate: [
                    {
                      trigger: false,
                      rules: [{ required: true, message: '请填写备注' }],
                    },
                  ],
                })}
                placeholder="请填写备注"
                type="string"
              >
                备注：
            </InputItem>
            <WhiteSpace size="xl" />
            <WhiteSpace size="xl" />
            <Flex>
              <Flex.Item>
                <Button onClick={dele}>退出</Button>
              </Flex.Item>
               <Flex.Item>
                <Button onClick={keep}>保存</Button>
              </Flex.Item>
           </Flex>
           </List>
        </List>
           
       <WhiteSpace size="xl" />
       <WhiteSpace size="xl" />
      </WingBlank>
    </div>
  );
};

// export default connect(({ tongue }) => ({
//   ...tongue,
// }))(TongueSavlePage);
export default connect(({ tongue }) => ({ ...tongue }))(createForm()(TongueSavlePage));
